package com.emip.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emip.bean.ExpFlagBean;
import com.emip.dao.ExpFlagDAO;
import com.emip.service.ExpFlagService;

@Service("expFlagService")
public class ExpFlagServiceImpl implements ExpFlagService {

	@Autowired
	ExpFlagDAO expFlagDAO;
	
	public ExpFlagBean addExpFlag(String flag, String desp, String inStat, String showNum) {
		ExpFlagBean newBean = new ExpFlagBean();
		newBean.setFlag(flag);
		newBean.setDesp(desp);
		newBean.setInStat(inStat);
		newBean.setShowNum(showNum);
		if (expFlagDAO.findExist(newBean)) {
			return null;
		}
		int newID = expFlagDAO.add(newBean);
		newBean.setId(newID);
		return newBean;
	}

	public Boolean deleteExpFlag(int id) {
		ExpFlagBean delBean = expFlagDAO.findByID(id);
		expFlagDAO.remove(delBean);
		return true;
	}

	public List<ExpFlagBean> getAll() {
		return expFlagDAO.getAll();
	}

	public ExpFlagBean getExpFlagByID(int id) {
		return expFlagDAO.findByID(id);
	}

	public ExpFlagBean updateExpFlag(int id, String flag, String desp,
			String inStat, String showNum) {
		ExpFlagBean newBean = expFlagDAO.findByID(id);
		newBean.setFlag(flag);
		newBean.setDesp(desp);
		newBean.setInStat(inStat);
		newBean.setShowNum(showNum);
		//查重，是否已经有相同的flag的记录存在
		//若有重复记录，则返回null
		if (expFlagDAO.findExist(newBean)) {
			return null;
		}
		expFlagDAO.update(newBean);
		return newBean;
	}

}
